package cn.edu.zjgsu.ito.service;

import cn.edu.zjgsu.ito.model.TeacherModel;

import com.jfinal.kit.EncryptionKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class AdminInfService {
	/*
	 * 张虎涛
	 * 2016/06/01
	 */
	
	public boolean checkPassword(String username, String oldPassword) {

		oldPassword = EncryptionKit.md5Encrypt(oldPassword);// 加密

		boolean tf = false;
		System.out.println("checkpassword");

		try {
			Record record=Db.findFirst("select * from admin where aNo=?",username);
			System.out.println("check record");
			tf = oldPassword.equals(record.get("aPwd"));
			System.out.println(tf);
			return tf;
		} catch (Exception e) {
			e.printStackTrace();
			return tf;
		}

	}
	
	public boolean updatePassword( String newPassword,String name) {

		newPassword = EncryptionKit.md5Encrypt(newPassword);// 加密
		System.out.println("update password");
		try {
			Db.update("update admin set aPwd=? where aNo=?", newPassword, name);
			System.out.println("update");
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}

	}

}
